package com.itheima.server.interceptor;

import com.itheima.model.domain.User;

/*
* 工具累：实现向threadlocal存储数据的方法
* */
public class UserHolder {
    private static ThreadLocal<User> t1 = new ThreadLocal<>();
//    存对象
    public static void set(User user){
        t1.set(user);
    }
//    取对象
    public static User get(){
        return t1.get();
    }
//用户id
    public static Long getUserId(){
        return t1.get().getId();
    }
    //手机号
    public static String getMobile(){
        return t1.get().getMobile();
    }
    //防止内存溢出
    public static void remove(){
        t1.remove();
    }
}
